<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.io.*"%>
<%@ page import="com.ichina.chat.dao.TrafficDao"%>
<%@ page import="com.ichina.chat.util.IPParser"%>
<%@ page import="com.ichina.chat.util.SourceUrl"%>
<%@ page import="com.ichina.chat.vo.Traffic"%>
<%@ page import="java.util.Map"%>
<%
	ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
			"applicationContext-*.xml");
	String Width = request.getParameter("Width");
	String Height = request.getParameter("Height");
	TrafficDao trafficDao = (TrafficDao) applicationContext
			.getBean("trafficDao");
	SourceUrl su = new SourceUrl();
	String sourceUrl = "";
	String targetUrl = "";
	String ip = request.getRemoteAddr();
	String area = "";
	Date visitDate = new Date();
	String userSystem = "";
	String userExplorer = "";
	String screenColor = "";
	String screenSize = "";
	String agent = ((HttpServletRequest) request)
			.getHeader("user-agent");
	String computerLanguage = "";
	String connectBusiness = "";
	String keywords = "";
	computerLanguage = request.getHeader("Accept-Language");
	screenSize = Width + "*" + Height;
	Map<String, String> client = su.getClientInfo(agent);
	screenColor=new String(request.getParameter("screenColor").getBytes("iso-8859-1"), "utf-8");
	userExplorer = client.get("userExplorer");
	userSystem = client.get("userSystem");
	sourceUrl = request.getParameter("fromUrl");
	targetUrl = request.getParameter("toUrl");
	System.out.println(sourceUrl);
	if (sourceUrl == null || sourceUrl.equals("")) {
		sourceUrl = "直接访问";
	} else {
		Map<String, String> m = su.search(sourceUrl);
		keywords = m.get("keywords");
		sourceUrl = m.get("sourceUrl");
		if (("").equals(sourceUrl)||null==sourceUrl) {
			sourceUrl = request.getParameter("fromUrl");
		}
	}
	IPParser w = new IPParser();
	w.setPath(new File("D:/qqwry.dat").toString());
	try {
		w.seek(ip);
	} catch (Exception e) {
		e.printStackTrace();
	}
	area = w.getCountry().toString();
	connectBusiness = w.getLocal().toString();
	if (w.getCountry() == null) {
		area = "未知IP地区";
		System.out.println("找不到此IP地区");
	} else {
		//System.out.println(area+ " " + connectBusiness);
	}
	Traffic t = new Traffic();
	t.setSourceUrl(sourceUrl);
	t.setTargetUrl(targetUrl);
	t.setIp(ip);
	t.setArea(area);
	t.setVisitDate(visitDate);
	t.setUserSystem(userSystem);
	t.setUserExplorer(userExplorer);
	t.setScreenColor(screenColor);
	t.setScreenSize(screenSize);
	t.setComputerLanguage(computerLanguage);
	t.setKeywords(keywords);
	t.setConnectBusiness(connectBusiness);
	trafficDao.addTraffic(t);
	trafficDao.queryTopkeywords();
%>

